package com.twu.biblioteca;

import java.util.ArrayList;
import java.util.List;

public class MainMenu {

    private List<String> menuOptions;
    public MainMenu()
    {
        menuOptions = new ArrayList<String>();
        menuOptions.add("Exit Program");
    }

    public void PrintMenu(ConsolePrinter consolePrinter)
    {
        consolePrinter.WriteLine("");
        consolePrinter.WriteLine("Enter an option:");
        int index = 1;
        for(String menuOption : menuOptions)
        {
            consolePrinter.WriteLine("Enter " + index++ + " - " + menuOption);
        }
    }

    public int GetSelectedMenuOption(ConsoleInput consoleInput)
    {
        try {
            int selectedOption = Integer.parseInt(consoleInput.ReadLine());
            if (selectedOption < 1 || selectedOption > menuOptions.size())
                return 0;
            return selectedOption;
        }
        catch(NumberFormatException exp)
        {
            return 0;
        }
    }

}
